/**
 * Created by iallai on 2/1/2018.
 */

import axios from 'axios'
import {CONFIG} from '@/config/env'

let API=CONFIG.PROJECT.API;


const query = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/op_tally/basics`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
  });



});
const get = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/op_tally/basics`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
    });



});

const line = (query={}) => new Promise((resolve, reject) => {


    axios.get(`${API.URL}/op_tally/line`,{
      params:query
    }).then(function(res){
        if(API.isOK(res.data)){
          resolve(res.data);
        }
      })
      .catch(function(err){
        reject("网络错误");
      });



  });
  const shops_pie = (query={}) => new Promise((resolve, reject) => {


    axios.get(`${API.URL}/op_tally/pie`,{
      params:query
    }).then(function(res){
        if(API.isOK(res.data)){
          resolve(res.data);
        }
      })
      .catch(function(err){
        reject("网络错误");
      });



  });
  const shops_count = (query={}) => new Promise((resolve, reject) => {


    axios.get(`${API.URL}/op_tally/count`,{
      params:query
    }).then(function(res){
        if(API.isOK(res.data)){
          resolve(res.data);
        }
      })
      .catch(function(err){
        reject("网络错误");
      });



  });



const applys = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/applies_shops/${query.id}`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
    });

});
const aduit = (query={}) => new Promise((resolve, reject) => {



  axios({
    method: 'post',
    url: `${API.URL}/applies_shops/${query.id}/applies`,
    params:query,

    }).then(function(res){
    if(API.isOK(res.data)){
      resolve(res.data);
    }else{
      reject(res.data.message);
    }
    }).catch(function(err){
    reject("网络错误");
    });

});

const detail = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/shops/${query.id}`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
    });

});






const credit = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/load_register`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }else {
        reject("获取认证信息错误");

      }
    })
    .catch(function(err){
      reject("获取认证信息错误");
    });

});


export {get,line,shops_pie,shops_count}

